#if !defined(__APP_BUFFER_H)
#define __APP_BUFFER_H
#include <pthread.h>

typedef struct {
    unsigned char *ptr;      // 数据指针
    int total_size; // 总大小
    int len;        // 已存储数据的长度
} SubBuffer;

typedef struct {
    SubBuffer *sub_buffers[2]; // 包含一个子缓冲区的数组
    int read_index;          // 读索引
    int write_index;         // 写索引
    pthread_mutex_t read_lock;  // 读锁
    pthread_mutex_t write_lock; // 写锁
} Buffer;

Buffer *app_buffer_init(int total_size);

void app_buffer_free(Buffer *buffer);

int app_buffer_write(Buffer *buffer, char *data, int len);

int app_buffer_read(Buffer *buffer, char *data_buf, int buf_len);

#endif // __APP_BUFFER_H
